package com.example.handler;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.common.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        // log.info("开始插入填充...");
        metaObject.setValue("createTime",DateUtil.now());
        metaObject.setValue("updateTime",DateUtil.now());
        metaObject.setValue("createUser", BaseContext.getCurrentId());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // log.info("开始更新填充...");

        metaObject.setValue("updateTime", DateUtil.now());
        metaObject.setValue("updateUser",BaseContext.getCurrentId());
    }
}